package cn.csust.net2.manager.client.chat;

import java.util.HashMap;

import cn.csust.net2.manager.shared.po.User;

/*
 * 聊天池
 */
public class ChatPool {

	
	User user;
	HashMap<Long, ChatTab> chatMap;
	
	
	public ChatPool(User user) {
		this.user = user;
		chatMap = new HashMap<Long, ChatTab>();
	}

	//显示聊天窗口
	public ChatTab showChatTab(User receiver) {
		ChatTab ct;
		long receiveID = receiver.getUserID();
		if(receiveID!=user.getUserID()){
			if (chatMap.get(receiveID) == null) {
				ct = new ChatTab(user, receiver);
				chatMap.put(receiveID, ct);	
				UserTreePanel.getChatTabPanel().add(ct);
				
			}else{
				ct = chatMap.get(receiveID);
				if(!ct.isActive()){				
					ct.setActive(true);
					UserTreePanel.getChatTabPanel().add(ct);
				}				
			}
			
			UserTreePanel.getChatTabPanel().setSelection(ct);
			return ct;
		}else{
			return null;
		}
		
	}

	
	//销毁关闭的窗口
	public void disposeChatTab(long l) {
		ChatTab ct = chatMap.get(l);
		ct.setActive(false);
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public HashMap<Long, ChatTab> getChatMap() {
		return chatMap;
	}

	public void setChatMap(HashMap<Long, ChatTab> chatMap) {
		this.chatMap = chatMap;
	}


}
